<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>测试</title>
	</head>
	<body>
		<script type="text/javascript">
			var tree = function() {        
				let data = [
					{
						"pID": "1",
						"name": "目录一",
						"menuID": "m1",
						"isContent": false
					}, {
						"pID": "1",
						"name": "目录二",
						"menuID": "m2",
						"isContent": false
					}, {
						"pID": "m1",
						"name": "目录一--菜单一",
						"menuID": "m11",
						"isContent": true
					}, {
						"pID": "m1",
						"name": "目录一--目录一",
						"menuID": "m12",
						"isContent": false
					}, {
						"pID": "m12",
						"name": "目录一--目录一--菜单一",
						"menuID": "m121",
						"isContent": true
					}, {
						"pID": "m2",
						"name": "目录二--菜单一",
						"menuID": "m21",
						"isContent": true
					}, {
						"pID": "m2",
						"name": "目录二--菜单二",
						"menuID": "m22",
						"isContent": true
					}
				];    
				let tree = []        
				for(let i = 0; i < data.length; i++) {          
					if(data[i].pID == '1') {            
						let obj = data[i]
						obj.list = []
						tree.push(obj)
						data.splice(i, 1)
						i--          
					}        
				}        
				console.log(tree)        
				menuList(tree)         
				function menuList(arr) {          
					if(data.length != 0) {            
						for(let i = 0; i < arr.length; i++) {              
							for(let j = 0; j < data.length; j++) {                
								if(data[j].pID == arr[i].menuID) {                  
									let obj = data[j]
									obj.list = []
									arr[i].list.push(obj)
									data.splice(j, 1)
									j--                
								}              
							}              
							menuList(arr[i].list)            
						}          
					}        
				}     
			}
			tree();
		</script>
	</body>

</html>